using GetWebData;
using System;
using System.Runtime.InteropServices;

namespace MSNet5
{
    class Program
    {
        delegate AC getAc(AC ac);
        static void Main(string[] args)
        {
            // 
            //RequestWebData requestWebData = new RequestWebData();
            //var value = requestWebData.Post("http://localhost:5001/Money3/SelectMoney33", new { id = "1", selecttype = "" });
            //Console.WriteLine(value);
            //value = requestWebData.Get("http://139.155.59.213/Money3/SelectMoney3/id='1'&selecttype=''");
            //Console.WriteLine(value);
            getAc get = new getAc(GetA);
            AC aC = new();
            aC.ss = "3";
            atcionValue(get);
            atcionValue2(OBJ =>
            {
                Console.WriteLine("2 " + OBJ.GetHashCode());
                //OBJ = aC;
                OBJ.ss = "4";
                Console.WriteLine("3 " + OBJ.GetHashCode());
            });
            Console.ReadLine();
        }
        private static AC GetA(AC ac)
        {
            return new AC() { ss = "1", cc = 2 };
        }
        private static void atcionValue2(Action<AC> AC)
        {
            AC ac = new AC();
            Console.WriteLine("1 "+ ac.GetHashCode());
            AC.Invoke(ac);
            Console.WriteLine("1 " + ac.GetHashCode());
        }
        private static void atcionValue(getAc aac)
        {
            AC ac = new AC();
            AC accc = new AC();
            Type o = ac.GetType();
            var o00 = ac.GetType();
            var oo = accc.GetHashCode();
            Console.WriteLine(ac.GetType().TypeHandle.Value);
            Console.WriteLine(getMemory(ac));
            Console.WriteLine(accc.GetType().TypeHandle.Value);
            Console.WriteLine(getMemory(accc));
            accc = aac?.Invoke(ac);
            Console.WriteLine(ac.GetType().TypeHandle.Value);
            Console.WriteLine(accc.GetType().TypeHandle.Value);
        }
        public static string getMemory(object o) // 获取引用类型的内存地址方法    
        {
            GCHandle h = GCHandle.Alloc(o, GCHandleType.WeakTrackResurrection);
            IntPtr addr = GCHandle.ToIntPtr(h);
            return "0x" + addr.ToString("X");
        }
    }
    class AC
    {
        public string ss = "";
        public int cc = 0;
        DateTime time = DateTime.Now;
    }
}
